package com.sxdz.models.common

import com.sxdz.constant.MessageConstant

/**
 * 返回Json格式
 * @param < T >
 */
public class JsonResult<T> implements Serializable {

    private String resCode;

    private String resMsg;

    private T resInfo;

    JsonResult(String resCode, String resMsg, T resInfo) {
        this.resCode = resCode
        this.resMsg = resMsg
        this.resInfo = resInfo
    }

    JsonResult(MessageConstant msgdefined, T resInfo) {
        this.resCode = msgdefined.getCode();
        this.resMsg = msgdefined.getDesc()
        this.resInfo = resInfo;
    }

    public String getResCode() {
        return resCode;
    }

    public void setResCode(String resCode) {
        this.resCode = resCode;
    }

    public T getResInfo() {
        return resInfo;
    }

    public void setResInfo(T resInfo) {
        this.resInfo = resInfo;
    }

    public String getResMsg() {
        return resMsg;
    }

    /**
     * 设置返回消息
     * @param msg ,消息常量设置
     * @param info，自定义返回消息
     * @param args，msg消息描述解析参数，格式参考String.format一样
     */
    public void setMsg(MessageConstant msg, T info,Object ... args) {
        this.resCode = msg.getCode();
        this.resMsg = msg.getMsg(args);
        this.resInfo = info;
    }
}
